package com.hzzy.utils;

import java.io.UnsupportedEncodingException;

import sun.misc.*; 

public class Base64Util {
	@SuppressWarnings("restriction")
	private static BASE64Encoder ENCODE = new BASE64Encoder();
	@SuppressWarnings("restriction")
	private static BASE64Decoder DECODER = new BASE64Decoder();
	// 加密  
    public static String getBase64(byte[] b) {  
//        byte[] b = null;  
        String s = null;  
//        try {  
//            b = str.getBytes("utf-8");  
//        } catch (UnsupportedEncodingException e) {  
//            e.printStackTrace();  
//        }  
        if (b != null) {  
            s = ENCODE.encode(b);  
        }  
        return s;  
    }  
  
    // 解密  
    public static String getFromBase64(String s) {  
        byte[] b = null;  
        String result = null;  
        if (s != null) {  
            try {  
                b = DECODER.decodeBuffer(s);  
                result = new String(b, "utf-8");  
            } catch (Exception e) {  
                e.printStackTrace();  
            }  
        }  
        return result;  
    }  
}
